package ants.util;

import java.io.IOException;
import java.util.Map;

import weibo4j.Oauth;
import weibo4j.Timeline;
import weibo4j.Weibo;
import weibo4j.examples.oauth2.Log;
import weibo4j.http.AccessToken;
import weibo4j.model.Status;
import weibo4j.model.StatusWapper;
import weibo4j.model.WeiboException;

public class WeiBoUtil {
	public static AccessToken getAccessTokenByCode(String code){
		Oauth oauth = new Oauth();
		AccessToken accessToken = null;
		try {
			accessToken=oauth.getAccessTokenByCode(code);
			System.out.println(accessToken);
		} catch (WeiboException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return accessToken;
	}
	
	public static StatusWapper getFriendsTimeline(AccessToken access_token) throws IOException {
		//String access_token =(String) AntsUtil.getPropertiesWithConfigProperty().get("accessToken");
		Weibo weibo = new Weibo();
		StatusWapper status = null;
		weibo.setToken(access_token.getAccessToken());
		Timeline tm = new Timeline();
		try {
			status = tm.getFriendsTimeline();
			for(Status s : status.getStatuses()){
				Log.logInfo(s.toString());
			}
			System.out.println(status.getNextCursor());
			System.out.println(status.getPreviousCursor());
			System.out.println(status.getTotalNumber());
			System.out.println(status.getHasvisible());
		} catch (WeiboException e) {
			e.printStackTrace();
		}
		return status;

	}
}
